// 验证appointment_management.js文件的关键问题
const fs = require('fs');
const path = require('path');

// 读取文件
const filePath = path.join(__dirname, 'pages', 'doctor', 'appointment_management', 'appointment_management.js');
const content = fs.readFileSync(filePath, 'utf8');

// 查找所有currentAppointmentId的位置
const findOccurrences = (text, regex) => {
  const results = [];
  let match;
  while ((match = regex.exec(text)) !== null) {
    results.push(match.index);
  }
  return results;
};

// 检查currentAppointmentId的所有出现位置
const currentAppointmentIdRegex = /currentAppointmentId/g;
const occurrences = findOccurrences(content, currentAppointmentIdRegex);
console.log(`currentAppointmentId出现${occurrences.length}次`);

// 检查data对象中是否有重复定义
const dataObjectRegex = /data\s*:\s*{[\s\S]*?}/;
const dataMatch = content.match(dataObjectRegex);
if (dataMatch) {
  const dataContent = dataMatch[0];
  const dataOccurrences = (dataContent.match(/currentAppointmentId/g) || []).length;
  console.log(`data对象中currentAppointmentId出现${dataOccurrences}次`);
  if (dataOccurrences > 1) {
    console.log('警告：data对象中存在重复的currentAppointmentId定义！');
  }
}

// 检查noteCurrentAppointmentId是否已正确替换
const noteCurrentAppointmentIdCount = (content.match(/noteCurrentAppointmentId/g) || []).length;
console.log(`noteCurrentAppointmentId出现${noteCurrentAppointmentIdCount}次`);

// 快速语法检查
let hasError = false;
try {
  new Function(content.replace(/Page\(/g, 'function PageMock(').replace(/wx\./g, '// wx.'));
  console.log('基本语法检查通过');
} catch (e) {
  console.log('语法错误: ' + e.message.substring(0, 100) + '...');
  hasError = true;
}

console.log('验证完成');
